import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
    sum:0,
    school:'尚硅谷',
    name:"前端"
}

const actions = {
    // jia(context,value){
    //     context.commit('JIA',value)//没有逻辑不需要action,直接提交mutation.
    // },
    // jian(context,value){
    //     context.commit('JIAN',value)//没有逻辑不需要action,直接提交mutation.   
    // },
    //当和为奇数时加
    jiaOdd(context,value){
        if(context.state.sum %2 != 0){
            context.commit('JIA',value)
        }
    },
    //等一等再加
    jiaWait(context,value){
        setTimeout(()=>{
            context.commit('JIA',value)
        },500)
    }
}

const mutations = {
    JIA(state,value){
        state.sum+=value
    },
    JIAN(state,value){
        state.sum-=value
    },
    Cheng(state,value){
        state.sum*=value
    }
}

const getters = {
    bigSum(state){
        return state.sum*10
    }
}

export default new Vuex.Store({
    state,
    actions,
    mutations,
    getters
})